package com.amir.common.mvp.base;

import android.content.Context;
import android.view.LayoutInflater;

import com.amir.common.holder.CommonViewHolder;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;


public abstract class BaseRecyclerViewAdapter<T> extends RecyclerView.Adapter<CommonViewHolder> {

    protected LayoutInflater layoutInflater;
    private CommonViewHolder mCommonViewHolder;
    protected List<T> dataList;
    protected Context mContext;

    public BaseRecyclerViewAdapter(Context context, List<T> dataList) {
        this.layoutInflater = LayoutInflater.from(context);
        this.dataList = dataList;
        this.mContext = context;
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void addData(List<T> dataList) {
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }

    public List<T> getData() {
        return dataList;
    }

    public void setHolder(CommonViewHolder holder) {
        this.mCommonViewHolder = holder;
    }

    public CommonViewHolder getHolder() {

        return mCommonViewHolder;
    }

    public void clearData() {
        this.dataList.clear();
    }

    public void removeData(int position) {
        this.dataList.remove(position);
        this.notifyDataSetChanged();
    }

    protected OnItemClickListener mOnItemClickListener;

    public interface OnItemClickListener {
        void onItem(int pos);

    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }


}
